package cn.seifly.demo.biz.system.service;

import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ruoyi.common.annotation.DataSource;
import com.ruoyi.common.enums.DataSourceType;
import cn.seifly.demo.biz.system.dao.SystemConfigDAO;
import cn.seifly.demo.biz.system.dao.entity.SystemConfigDO;
import cn.seifly.demo.service.system.mapper.SystemConfigMapper;
import cn.seifly.demo.biz.system.service.vo.SystemConfigVO;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import java.util.List;

/**
 * 
 * @ClassName: SystemConfigService
 * @Description: TODO
 * @author: sxf
 * @date: 2019年4月28日 上午10:53:58
 */
@Service
public class SystemConfigService{

    @Resource
    private SystemConfigDAO systemConfigDAO;
    @Resource
    private SystemConfigMapper systemConfigMapper;
    /**
     *
     * @Title: queryListByParams
     * @Description:  分页查询
     * @param systemConfigVO
     * @return
     * @return: PageResult<SystemConfigDO
     */
 @DataSource(DataSourceType.MASTER)
 public IPage<SystemConfigDO> queryListByParams(SystemConfigVO systemConfigVO) {
     SystemConfigDO systemConfigDO = BeanUtil.copyProperties(systemConfigVO, SystemConfigDO.class);
     //systemConfigDAO.insert(systemConfigDO);
     systemConfigMapper.selectByPrimaryKey(1);
     LambdaQueryWrapper<SystemConfigDO> wrapper = SystemConfigDAO.getWrapper(systemConfigVO);
     List<SystemConfigDO> list =systemConfigDAO.selectList(wrapper);
     IPage<SystemConfigDO> page = new Page<>(systemConfigVO.getPageNum(), systemConfigVO.getPageSize()); // 分页查询
     IPage<SystemConfigDO> pageList = systemConfigDAO.selectPage(page, wrapper);
     return pageList;
 }

 /**
  * 
  * @Title: create
  * @Description: 添加
  * @param systemConfigVO
  * @return
  * @return: SystemConfigDO 
  */
 public Integer create (SystemConfigVO systemConfigVO) {
     SystemConfigDO systemConfig = BeanUtil.copyProperties(systemConfigVO, SystemConfigDO.class);
     return systemConfigDAO.insert(systemConfig);
 }

 /**
  * 
  * @Title: update
  * @Description: 修改
  * @param systemConfigVO
  * @return
  * @return: Integer
  */
 public Integer update(SystemConfigVO systemConfigVO) {
     SystemConfigDO systemConfig = systemConfigVO.getDO();
     int rows=systemConfigDAO.updateById(systemConfig);
     return rows;
 }

 /**
  * 
  * @Title: delete
  * @Description: 删除
  * @param systemConfigVO
  * @return
  * @return: Integer
  */
 public Integer delete (SystemConfigVO systemConfigVO) {
     int rows=0;//systemConfigDAO.deleteById(systemConfigVO.getId());
     return rows;
 }

 /**
  * 
  * @Title: getDetail
  * @Description:  查询详情
  * @param systemConfigVO
  * @return
  * @return: SystemConfigDO 
  */
 public SystemConfigDO getDetail(SystemConfigVO systemConfigVO) {
     LambdaQueryWrapper<SystemConfigDO> wrapper = SystemConfigDAO.getWrapper(systemConfigVO);
     List<SystemConfigDO> list = systemConfigDAO.selectList(wrapper);
     if(CollectionUtils.isEmpty(list)){
     return null;
     }
     SystemConfigDO systemConfigDO = list.get(0);
     return systemConfigDO;
 }

}